package com.erp.ae.controller;

import com.erp.ae.service.IAeProductGroupService;
import com.ruoyi.common.core.domain.R;
import com.erp.ae.utils.AeApiUtils;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.gather.api.domain.dto.SendProductGroupDto;
import com.ruoyi.gather.api.domain.dto.StoreGroupDto;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erp/productGroup")
public class AeProductGroupController {

    private final IAeProductGroupService iAeProductGroupService;

    /**
     * 获取店铺类目分组
     */
    @GetMapping("/queryStoreGroupList")
    public R<Object> queryStoreGroupList(Long storeId) {
        return iAeProductGroupService.queryStoreGroupList(storeId);
    }

    /**
     * 获取店铺类目分组
     */
//    @InnerAuth
    @GetMapping("/queryStoreGroupListInnerAuth/{storeId}")
    public R<Object> queryStoreGroupListInnerAuth(@PathVariable("storeId") Long storeId) {
        return iAeProductGroupService.queryStoreGroupList(storeId);
    }

    /**
     * 创建店铺类目分组
     */
    @PostMapping("/createStoreGroup")
    public R<Object> createStoreGroup(@RequestBody Map<String, Object> map) {
        return iAeProductGroupService.createStoreGroup(map);
    }

    /**
     * 创建店铺类目分组
     */
    @PostMapping("/createStoreGroupInnerAuth")
    public R<Object> createStoreGroupInnerAuth(@RequestBody() StoreGroupDto dto) {
        Map<String,Object> map = new HashMap<>();
        map.put("memo",dto.getMemo());
        map.put("name",dto.getGroupName());
        map.put("parent_id",dto.getParentId());
        map.put("store_id",dto.getStoreId());
        return iAeProductGroupService.createStoreGroup(map);
    }

    /**
     * 绑定商品至分组
     */
    @PostMapping("/bindingProdudtForGroupInnerAuth")
    public R<Object> bindingProdudtForGroupInnerAuth(@RequestBody SendProductGroupDto dto) {
        String storeId = dto.getStoreId();
        String groupId=  dto.getGroupId();
        String productGroups = dto.getProductGroups();
       return iAeProductGroupService.bindingProdudtForGroup(storeId,groupId,productGroups);

    }

    /**
     * 绑定商品至分组
     */
    @PostMapping("/bindingProdudtForGroup")
    public R<Object> bindingProdudtForGroup(@RequestBody Map<String, Object> map) {
        String storeId = (String)map.get("storeId");
        String groupId=  (String) map.get("groupId");
        String productGroups = (String) map.get("productGroups");
       return iAeProductGroupService.bindingProdudtForGroup(storeId,groupId,productGroups);

    }

    /**
     * 确认商品是否还在店铺中
     */
    @PostMapping("/queryProductGroupIdByProductId")
    public R<Object> queryProductGroupIdByProductId(@RequestBody Map<String, Object> map) {
        String storeId = (String) map.get("storeId");
        List<Long> ids = (List<Long>) map.get("ids");
        String groupId = (String) map.get("groupId");
      return iAeProductGroupService.queryProductGroupIdByProductId(storeId,ids,groupId);
    }

    /**
     * 确认商品是否还在店铺中 内部用
     */
    @PostMapping("/queryProductGroupIdByProductIdInnerAuth")
    public R<Object> queryProductGroupIdByProductIdInnerAuth(@RequestBody Map<String, Object> map) {
        String storeId = (String) map.get("storeId");
        List<Long> ids = (List<Long>) map.get("ids");
        String groupId = (String) map.get("groupId");
      return iAeProductGroupService.queryProductGroupIdByProductId(storeId,ids,groupId);
    }

}
